package com.sztle.admodule.resp;

import com.sztle.admodule.someutils.Utils;

import java.io.File;
import java.util.concurrent.TimeUnit;

import okhttp3.Cache;
import okhttp3.OkHttpClient;
import okhttp3.logging.HttpLoggingInterceptor;


public class CustomOkHttpClient {

    //读超时长，单位：毫秒
    public static final int READ_TIME_OUT = 35000;
    //连接时长，单位：毫秒
    public static final int CONNECT_TIME_OUT = 30000;

    private OkHttpClient mOkHttpClient;

    public OkHttpClient getOkHttpClient() {

        HttpLoggingInterceptor logInterceptor = new HttpLoggingInterceptor();
        File cacheFile = new File(Utils.getApp().getCacheDir(), "Artifit");
        Cache cache = new Cache(cacheFile, 1024 * 1024 * 100); //100Mb

        mOkHttpClient = new OkHttpClient.Builder()
                .readTimeout(READ_TIME_OUT, TimeUnit.MILLISECONDS)
                .connectTimeout(CONNECT_TIME_OUT, TimeUnit.MILLISECONDS)
                .addInterceptor(logInterceptor)
                .build();
        return mOkHttpClient;
    }

}
